package com.ykdl.member.kid.adapters;

import java.util.ArrayList;

import com.ykdl.member.kid.R;
import com.ykdl.member.kid.adapters.MyReanswerListAdapter.ViewHolder;
import com.ykdl.member.kid.beans.OfficialMessageBean;
import com.ykdl.member.kid.image.ImageOptionsFactory;
import com.ykdl.member.kid.util.DateUtil;
import com.ykdl.member.kid.widget.AsyncImageView;

import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class OfficialMessageAdapter  extends BaseAdapter{
	private Activity mContext ;
	private String TAG ;
	private ArrayList<OfficialMessageBean>  list;
	public OfficialMessageAdapter(Activity context,String tag){
		this.mContext = context;
		TAG = tag ;
	}
	public void setlist(ArrayList<OfficialMessageBean>  list) {
		this.list=list ;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if (list != null) {
			return list.size();
		} else {
			return 0;
		}
	}

	@Override
	public Object getItem(int position) {
		Log.e("----", "----------getItem-----arg2:"+position);
		// TODO Auto-generated method stub
//		if (getCount() != 0) {
//			return list.get(position-1);
//		} else {
//			return null;
//		}
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null ;
		if (convertView==null) {
			convertView = RelativeLayout.inflate(mContext,
					R.layout.officialmessageadapter_item, null);
			holder = new ViewHolder();
			 holder.user_head =  (AsyncImageView) convertView.findViewById(R.id.user_head);
			 holder.user_name=  (TextView) convertView.findViewById(R.id.user_name);
			 holder.user_time=  (TextView) convertView.findViewById(R.id.user_time);
			 holder.user_content=  (TextView) convertView.findViewById(R.id.user_content);
			 convertView.setTag(holder);
		}else {
			holder = (ViewHolder)convertView.getTag();
		}
		if (list.get(position).getFrom_actor().getAvatar_file_meta()!=null) {
			String url = list.get(position).getFrom_actor().getAvatar_file_meta().getDownload_urls().getSmal().getUrl();
			holder.user_head.setUrl(TAG, url, ImageOptionsFactory.getSmallPortraitOptions(mContext));
		}
		holder.user_name.setText(list.get(position).getFrom_actor().getDisplay_name());
		holder.user_content.setText(list.get(position).getContent());
		String time = DateUtil.gettimeDate(list.get(position).getCreated_time());
		holder.user_time.setText(time);
		return convertView;
	}
	class ViewHolder {
		 AsyncImageView user_head ;
		 TextView  user_name,user_time,
		user_content;
	}

}
